package uk.ac.aber.Blockmation;

import java.awt.Color;

import java.util.Hashtable;


/**
 * Maintains association between letters/characters and colors as
 * color-to-letter and letter-to-color two hashtables. Necessary for Scotty
 * txt file type conversions.  Prefilled with about 200 web-safe colors and
 * corresponding letters. 
 *
 * @author Aron
 */
public class OurColors
{
    private Hashtable<Character, Color> letters = new Hashtable<Character, Color>();
    private Hashtable<Color, Character> colors = new Hashtable<Color, Character>();

    /**
    * Constructs two hash tables for both letters and colors as keys.
    */
    public OurColors()
    {
        fillWithOurColors();
    }

    /**
     * Adds another letter and corresponding color to the tables.
     *
     * @param letter - the letter to add
     * @param color - its corresponding letter
     */
    public void add(char letter, Color color)
    {
        letters.put(letter, color);
        colors.put(color, letter);
    }

    /**
     * Gets the color associated with the letter.
     *
     * @param letter - to find the color associated with it
     *
     * @return color that the letter corresponds to. The default  is
     *         Color.black for searched letter that doesn't exist in  the
     *         table.
     */
    public Color get(char letter)
    {
        // default color if no association found
        Color result = Color.black;

        try
        {
            result = letters.get(letter);
        }
        catch (NullPointerException e)
        {
            //do nothing here, give default color
            result = Color.black;
        }

        return result;
    }

    /**
     * Gets the letter/character associated with the color.
     *
     * @param color - to find the letter associated with it
     *
     * @return letter/character that the color corresponds to. The default
     *         character 'r' for searched color that  doesn't exist in the
     *         table.
     */
    public char get(Color color)
    {
        char result = 'r';

        try
        {
            result = colors.get(color);
        }
        catch (NullPointerException e)
        {
            //do nothing here, give default color
            result = 'r';
        }

        return result;
    }

    /**
     * Used internally to fill the default letters-to-colors
     * associations.
     */
    private void fillWithOurColors()
    {
        /*
        this.add('b', Color.blue);
        this.add('r', Color.black);
        this.add('l', Color.gray);
        this.add('a', Color.white);
         */
        
        //map.add(n'x', new Color (red, green, blue));
        
        this.add('r', new Color(0, 0, 0)); // black
        this.add('a', new Color(255, 255, 255)); // white
        this.add('l', new Color(204, 204, 204)); // grey
        this.add('b', new Color(0, 0, 255)); // blue
        
    	this.add('!', new Color(0, 0, 0));
    	this.add('"', new Color(51, 0, 0));
    	this.add('#', new Color(102, 0, 0));
    	this.add('$', new Color(153, 0, 0));
    	this.add('%', new Color(204, 0, 0));
    	this.add('&', new Color(255, 0, 0));
    	this.add('(', new Color(0, 0, 51));
    	this.add(')', new Color(51, 0, 51));
    	this.add('*', new Color(102, 0, 51));
    	this.add('+', new Color(153, 0, 51));
    	this.add(',', new Color(204, 0, 51));
    	this.add('-', new Color(255, 0, 51));
    	this.add('.', new Color(0, 0, 102));
    	this.add('/', new Color(51, 0, 102));
    	this.add('0', new Color(102, 0, 102));
    	this.add('1', new Color(153, 0, 102));
    	this.add('2', new Color(204, 0, 102));
    	this.add('3', new Color(255, 0, 102));
    	this.add('4', new Color(0, 0, 153));
    	this.add('5', new Color(51, 0, 153));
    	this.add('6', new Color(102, 0, 153));
    	this.add('7', new Color(153, 0, 153));
    	this.add('8', new Color(204, 0, 153));
    	this.add('9', new Color(255, 0, 153));
    	this.add(':', new Color(0, 0, 204));
    	this.add(';', new Color(51, 0, 204));
    	this.add('<', new Color(102, 0, 204));
    	this.add('=', new Color(153, 0, 204));
    	this.add('>', new Color(204, 0, 204));
    	this.add('?', new Color(255, 0, 204));
    	this.add('@', new Color(0, 0, 255));
    	this.add('A', new Color(51, 0, 255));
    	this.add('B', new Color(102, 0, 255));
    	this.add('C', new Color(153, 0, 255));
    	this.add('D', new Color(204, 0, 255));
    	this.add('E', new Color(255, 0, 255));
    	this.add('F', new Color(0, 51, 0));
    	this.add('G', new Color(51, 51, 0));
    	this.add('H', new Color(102, 51, 0));
    	this.add('I', new Color(153, 51, 0));
    	this.add('J', new Color(204, 51, 0));
    	this.add('K', new Color(255, 51, 0));
    	this.add('L', new Color(0, 51, 51));
    	this.add('M', new Color(51, 51, 51));
    	this.add('N', new Color(102, 51, 51));
    	this.add('O', new Color(153, 51, 51));
    	this.add('P', new Color(204, 51, 51));
    	this.add('Q', new Color(255, 51, 51));
    	this.add('R', new Color(0, 51, 102));
    	this.add('S', new Color(51, 51, 102));
    	this.add('T', new Color(102, 51, 102));
    	this.add('U', new Color(153, 51, 102));
    	this.add('V', new Color(204, 51, 102));
    	this.add('W', new Color(255, 51, 102));
    	this.add('X', new Color(0, 51, 153));
    	this.add('Y', new Color(51, 51, 153));
    	this.add('Z', new Color(102, 51, 153));
    	this.add('[', new Color(153, 51, 153));
    	this.add(']', new Color(204, 51, 153));
    	this.add('^', new Color(255, 51, 153));
    	this.add('_', new Color(0, 51, 204));
    	this.add('`', new Color(51, 51, 204));
    	//this.add('a', new Color(102, 51, 204));
    	//this.add('b', new Color(153, 51, 204));
    	this.add('c', new Color(204, 51, 204));
    	this.add('d', new Color(255, 51, 204));
    	this.add('e', new Color(0, 51, 255));
    	this.add('f', new Color(51, 51, 255));
    	this.add('g', new Color(102, 51, 255));
    	this.add('h', new Color(153, 51, 255));
    	this.add('i', new Color(204, 51, 255));
    	this.add('j', new Color(255, 51, 255));
    	this.add('k', new Color(0, 102, 0));
    	//this.add('l', new Color(51, 102, 0));
    	this.add('m', new Color(102, 102, 0));
    	this.add('n', new Color(153, 102, 0));
    	this.add('o', new Color(204, 102, 0));
    	this.add('p', new Color(255, 102, 0));
    	this.add('q', new Color(0, 102, 51));
    	//this.add('r', new Color(51, 102, 51));
    	this.add('s', new Color(102, 102, 51));
    	this.add('t', new Color(153, 102, 51));
    	this.add('u', new Color(204, 102, 51));
    	this.add('v', new Color(255, 102, 51));
    	this.add('w', new Color(0, 102, 102));
    	this.add('x', new Color(51, 102, 102));
    	this.add('y', new Color(102, 102, 102));
    	this.add('z', new Color(153, 102, 102));
    	this.add('{', new Color(204, 102, 102));
    	this.add('|', new Color(255, 102, 102));
    	this.add('}', new Color(0, 102, 153));
    	this.add('~', new Color(51, 102, 153));
    	this.add('¡', new Color(102, 102, 153));
    	this.add('¢', new Color(153, 102, 153));
    	this.add('£', new Color(204, 102, 153));
    	this.add('¤', new Color(255, 102, 153));
    	this.add('¥', new Color(0, 102, 204));
    	this.add('¦', new Color(51, 102, 204));
    	this.add('§', new Color(102, 102, 204));
    	this.add('¨', new Color(153, 102, 204));
    	this.add('©', new Color(204, 102, 204));
    	this.add('ª', new Color(255, 102, 204));
    	this.add('«', new Color(0, 102, 255));
    	this.add('¬', new Color(51, 102, 255));
    	this.add('­', new Color(102, 102, 255));
    	this.add('®', new Color(153, 102, 255));
    	this.add('¯', new Color(204, 102, 255));
    	this.add('°', new Color(255, 102, 255));
    	this.add('±', new Color(0, 153, 0));
    	this.add('²', new Color(51, 153, 0));
    	this.add('³', new Color(102, 153, 0));
    	this.add('´', new Color(153, 153, 0));
    	this.add('µ', new Color(204, 153, 0));
    	this.add('¶', new Color(255, 153, 0));
    	this.add('·', new Color(0, 153, 51));
    	this.add('¸', new Color(51, 153, 51));
    	this.add('¹', new Color(102, 153, 51));
    	this.add('º', new Color(153, 153, 51));
    	this.add('»', new Color(204, 153, 51));
    	this.add('¼', new Color(255, 153, 51));
    	this.add('½', new Color(0, 153, 102));
    	this.add('¾', new Color(51, 153, 102));
    	this.add('¿', new Color(102, 153, 102));
    	this.add('€', new Color(153, 153, 102));
    	this.add('?', new Color(204, 153, 102));
    	this.add('‚', new Color(255, 153, 102));
    	this.add('ƒ', new Color(0, 153, 153));
    	this.add('„', new Color(51, 153, 153));
    	this.add('…', new Color(102, 153, 153));
    	this.add('†', new Color(153, 153, 153));
    	this.add('‡', new Color(204, 153, 153));
    	this.add('ˆ', new Color(255, 153, 153));
    	this.add('‰', new Color(0, 153, 204));
    	this.add('Š', new Color(51, 153, 204));
    	this.add('‹', new Color(102, 153, 204));
    	this.add('Œ', new Color(153, 153, 204));
    	this.add('?', new Color(204, 153, 204));
    	this.add('Ž', new Color(255, 153, 204));
    	this.add('?', new Color(0, 153, 255));
    	this.add('?', new Color(51, 153, 255));
    	this.add('‘', new Color(102, 153, 255));
    	this.add('’', new Color(153, 153, 255));
    	this.add('“', new Color(204, 153, 255));
    	this.add('”', new Color(255, 153, 255));
    	this.add('•', new Color(0, 204, 0));
    	this.add('–', new Color(51, 204, 0));
    	this.add('—', new Color(102, 204, 0));
    	this.add('˜', new Color(153, 204, 0));
    	this.add('™', new Color(204, 204, 0));
    	this.add('š', new Color(255, 204, 0));
    	this.add('›', new Color(0, 204, 51));
    	this.add('œ', new Color(51, 204, 51));
    	this.add('?', new Color(102, 204, 51));
    	this.add('ž', new Color(153, 204, 51));
    	this.add('Ÿ', new Color(204, 204, 51));
    	this.add(' ', new Color(255, 204, 51));
    	this.add('¡', new Color(0, 204, 102));
    	this.add('¢', new Color(51, 204, 102));
    	this.add('£', new Color(102, 204, 102));
    	this.add('¤', new Color(153, 204, 102));
    	this.add('¥', new Color(204, 204, 102));
    	this.add('¦', new Color(255, 204, 102));
    	this.add('§', new Color(0, 204, 153));
    	this.add('¨', new Color(51, 204, 153));
    	this.add('©', new Color(102, 204, 153));
    	this.add('ª', new Color(153, 204, 153));
    	this.add('«', new Color(204, 204, 153));
    	this.add('¬', new Color(255, 204, 153));
    	this.add('­', new Color(0, 204, 204));
    	this.add('®', new Color(51, 204, 204));
    	this.add('¯', new Color(102, 204, 204));
    	this.add('°', new Color(153, 204, 204));
    	this.add('±', new Color(204, 204, 204));
    	this.add('²', new Color(255, 204, 204));
    	this.add('³', new Color(0, 204, 255));
    	this.add('´', new Color(51, 204, 255));
    	this.add('µ', new Color(102, 204, 255));
    	this.add('¶', new Color(153, 204, 255));
    	this.add('·', new Color(204, 204, 255));
    	this.add('¸', new Color(255, 204, 255));
    	this.add('¹', new Color(0, 255, 0));
    	this.add('º', new Color(51, 255, 0));
    	this.add('»', new Color(102, 255, 0));
    	this.add('¼', new Color(153, 255, 0));
    	this.add('½', new Color(204, 255, 0));
    	this.add('¾', new Color(255, 255, 0));
    	this.add('¿', new Color(0, 255, 51));
    	this.add('‚', new Color(51, 255, 51));
    	this.add('ƒ', new Color(102, 255, 51));
    	this.add('„', new Color(153, 255, 51));
    	this.add('…', new Color(204, 255, 51));
    	this.add('†', new Color(255, 255, 51));
    	this.add('‡', new Color(0, 255, 102));
    	this.add('Œ', new Color(51, 255, 102));
    	this.add('?', new Color(102, 255, 102));
    	this.add('Ž', new Color(153, 255, 102));
    	this.add('?', new Color(204, 255, 102));
    	this.add('?', new Color(255, 255, 102));
    	this.add('‘', new Color(0, 255, 153));
    	this.add('˜', new Color(51, 255, 153));
    	this.add('™', new Color(102, 255, 153));
    	this.add('š', new Color(153, 255, 153));
    	this.add('›', new Color(204, 255, 153));
    	this.add('¹', new Color(255, 255, 153));
    	this.add('º', new Color(0, 255, 204));
    	this.add('½', new Color(51, 255, 204));
    	this.add('¾', new Color(102, 255, 204));
    	this.add('?', new Color(153, 255, 204));
    	this.add('‚', new Color(204, 255, 204));
    	this.add('ƒ', new Color(255, 255, 204));
    	this.add('„', new Color(0, 255, 255));
    	this.add('‡', new Color(51, 255, 255));
    	this.add('ˆ', new Color(102, 255, 255));
    	this.add('?', new Color(153, 255, 255));
    	this.add('‘', new Color(204, 255, 255));

    }

	public Hashtable<Character, Color> getLetters() {
		return letters;
	}

}
